//
//  SICPSDKCommon.m
//  BlueToothSDK
//
//  Created by Piccolo on 2017/11/11.
//  Copyright © 2017年 Piccolo. All rights reserved.
//

#import "SICPSDKCommon.h"


@implementation SICPSDKCommon

+ (BOOL)managerIsScanning:(CBCentralManager *)manager defBool:(BOOL)defBoolean {
    return [[SICPSDKCommon getDeviceVersion] integerValue] < 9.0 ? defBoolean :  [manager isScanning];
}
+ (NSString *)getDeviceVersion {
    return [[UIDevice currentDevice] systemVersion];
}

+ (BOOL)delegateExist:(id)delegate delegate:(Protocol *)protocol selector:(SEL)aSelector{
    NSLog(@"@22--%@---%d---%d", delegate, [delegate conformsToProtocol:protocol], [delegate respondsToSelector:aSelector]);
    return delegate && [delegate conformsToProtocol:protocol] && [delegate respondsToSelector:aSelector];
}
+ (BOOL)judgeExist:(NSObject *)obj{
    if ([obj isKindOfClass:[NSString class]]) {
        NSString *objStr = (NSString *)obj;
        return objStr != nil && ![objStr isEqualToString:@""];
    }
    if ([obj isKindOfClass:[NSArray class]] || [obj isKindOfClass:[NSMutableArray class]]){
        NSArray *objArray = (NSArray *)obj;
        return objArray != nil && [objArray count] != 0;
    }
    if ([obj isKindOfClass:[NSDictionary class]] || [obj isKindOfClass:[NSMutableDictionary class]]){
        NSDictionary *objDictionary = (NSDictionary *)obj;
        return objDictionary != nil && [objDictionary count] != 0;
    }
    return NO;
}

+ (BOOL)isExistDic:(NSDictionary *)dic key:(NSString *)key{
    //    return [dic.allKeys containsObject:key] && dic[key] != [NSNull null] && [dic[key] count] > 0;
    if ([dic.allKeys containsObject:key]) {
        if (dic[key] != [NSNull null]){
            if ([dic[key] isKindOfClass:[NSArray class]]) {
                return [dic[key] count];
            }
            else{
                return YES;
            }
        }
        else{
            return NO;
        }
    }
    else{
        return NO;
    }
}

+ (NSString *)convertDateToString:(NSDate *)date withFormatter:(NSString *)formatterStr{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:formatterStr];
    return [formatter stringFromDate:date];
}

+ (NSDate *)convertStringToDate:(NSString *)dateStr withFormatter:(NSString *)formatterStr{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:formatterStr];
    return [formatter dateFromString:dateStr];
}
@end
